//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include <IniFiles.hpp>

#include "LangMan.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

void __fastcall TLangManager::Save(TStringList *s, TForm *f)
{
    class TAC : public TControl
    {
        __published:
            __property Caption;
            __property Hint;
    };

    AnsiString text;

//    s->Clear();

//    s->Add("Caption="+f->Caption);

    for(int i= 0; i < f->ComponentCount; i++)
    {
        text= "";

        if(f->Components[i]->ClassNameIs("TButton") ||
           f->Components[i]->ClassNameIs("TLabel") ||
           f->Components[i]->ClassNameIs("TBitBtn") ||
           f->Components[i]->ClassNameIs("TSpeedButton") ||
           f->Components[i]->ClassNameIs("TTrackBar") ||
           f->Components[i]->ClassNameIs("TEdit"))
        {
            TAC *c= reinterpret_cast < TAC *> (f->Components[i]);
            text= c->Caption+"$"+c->Hint;
        }

        if(f->Components[i]->ClassNameIs("TComboBox"))
        {
            TAC *c= reinterpret_cast < TAC *> (f->Components[i]);
            text= c->Hint;
        }

        if(!text.IsEmpty())
            s->Add(f->Components[i]->Name+"="+text);
    }
}

//
void __fastcall TLangManager::Load(TStringList *s, TForm *f)
{
    class TAC : public TControl
    {
        __published:
            __property Caption;
            __property Hint;
    };

    AnsiString g, t;

    for(int i= 0; i < f->ComponentCount; i++)
    {
        if(f->Components[i]->ClassNameIs("TButton") ||
           f->Components[i]->ClassNameIs("TLabel") ||
           f->Components[i]->ClassNameIs("TBitBtn") ||
           f->Components[i]->ClassNameIs("TSpeedButton") ||
           f->Components[i]->ClassNameIs("TTrackBar") ||
           f->Components[i]->ClassNameIs("TEdit"))
        {
            TAC *c= reinterpret_cast < TAC *> (f->Components[i]);

            g= s->Values[f->Components[i]->Name];

            if(!g.IsEmpty())
            {
                int p= g.Pos("$");
                
                t= g.SubString(1, p-1);
                if(!t.IsEmpty())
                    c->Caption= t;

                t= g.SubString(p+1, g.Length()-p);
                if(!t.IsEmpty())
                    c->Hint= t;
            }
        }

        if(f->Components[i]->ClassNameIs("TComboBox"))
        {
            TAC *c= reinterpret_cast < TAC *> (f->Components[i]);

            t= s->Values[f->Components[i]->Name];

            if(!t.IsEmpty())
                c->Hint= t;
        }
    }
}


